package com.smarthealthcare.device.service.impl;

import java.util.List;

import com.smarthealthcare.device.mapper.ManufacturerMapper;
import com.smarthealthcare.devicetype.mapper.DevicetypeMapper;
import com.smarthealthcare.mapper.DepartmentMapper;
import com.smarthealthcare.patient.mapper.BeinhospitalMapper;
import com.smarthealthcare.system.mapper.SysUserMapper;
import com.smarthealthcare.ward.mapper.WardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smarthealthcare.device.mapper.DeviceMapper;
import com.smarthealthcare.device.domain.Device;
import com.smarthealthcare.device.service.IDeviceService;

/**
 * 设备列表Service业务层处理
 *
 * @author YF
 * @date 2024-11-24
 */
@Service
public class DeviceServiceImpl implements IDeviceService {
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private ManufacturerMapper manufacturerMapper;
    @Autowired
    private DevicetypeMapper devicetypeMapper;
    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private WardMapper wardMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询设备列表
     *
     * @param id 设备列表主键
     * @return 设备列表
     */
    @Override
    public Device selectDeviceById(Long id) {
        return deviceMapper.selectDeviceById(id);
    }

    /**
     * 查询设备列表列表
     *
     * @param device 设备列表
     * @return 设备列表
     */
    @Override
    public List<Device> selectDeviceList(Device device) {
        List<Device> list = deviceMapper.selectDeviceList(device);
        for (Device de : list) {
            Long companyId = de.getCompanyId();
            de.setManufacturer(manufacturerMapper.selectManufacturerById(companyId));
            Long equipmentId = de.getEquipmentId();
            de.setDevicetype(devicetypeMapper.selectDevicetypeById(equipmentId));
            Long checkRoom = de.getCheckRoom();
            de.setDepartment(departmentMapper.selectDepartmentById(checkRoom));
            Long location = de.getLocation();
            de.setWard(wardMapper.selectWardById(location));
            Long operateId = de.getOperateId();
            de.setSysUser(sysUserMapper.selectUserById(operateId));
        }
        return list;
    }

    /**
     * 新增设备列表
     *
     * @param device 设备列表
     * @return 结果
     */
    @Override
    public int insertDevice(Device device) {
        return deviceMapper.insertDevice(device);
    }

    /**
     * 修改设备列表
     *
     * @param device 设备列表
     * @return 结果
     */
    @Override
    public int updateDevice(Device device) {
        return deviceMapper.updateDevice(device);
    }

    /**
     * 批量删除设备列表
     *
     * @param ids 需要删除的设备列表主键
     * @return 结果
     */
    @Override
    public int deleteDeviceByIds(Long[] ids) {
        return deviceMapper.deleteDeviceByIds(ids);
    }

    /**
     * 删除设备列表信息
     *
     * @param id 设备列表主键
     * @return 结果
     */
    @Override
    public int deleteDeviceById(Long id) {
        return deviceMapper.deleteDeviceById(id);
    }
}
